﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;  // pour Sql Server.

namespace AFCEPF.BankApplication.DAL
{
    public class SqlServerDbAccessor : AbstractDbAccessor
    {
        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="mappedObject">The mapped object.</param>
        public SqlServerDbAccessor(string connectionString, DataMapper mappedObject)
            : base(connectionString, mappedObject)
        {
            // On instancie le bon type de générateur SQL
            // pour ce DbAccessor..
            _sqlGenerator = new SqlServerSqlGenerator(mappedObject);

        }

        /// <summary>
        /// Inits the strongly-typed db objects
        /// (for Sql Server, or My Sql).
        /// </summary>
        protected override void initTypedDbObjects()
        {
            Connection  = newConnection();
            Command     = newCommand();
            Adapter     = new SqlDataAdapter();
        }

        /// <summary>
        /// Gets a new connection.
        /// </summary>
        /// <returns>
        /// a new connection.
        /// </returns>
        protected override IDbConnection newConnection()
        {
            return new SqlConnection();
        }

        /// <summary>
        /// Gets a new Command.
        /// </summary>
        /// <returns>
        /// a new Command.
        /// </returns>
        protected override IDbCommand newCommand()
        {
            return new SqlCommand();
        }
    }
}
